<%-- 
    Document   : movieList
    Created on : May 1, 2013, 5:39:55 PM
    Author     : DevSteve
--%>
<%@page import="java.util.List"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="db.DB"%>
<%@page import="db.MovieObj"%>
<%@page import="java.io.*"%>
<%
    String name = request.getParameter("name");
    String type = request.getParameter("type");
    String rating = request.getParameter("rating");
    String distr = request.getParameter("distr");
    String copies = request.getParameter("copies");
    String description = request.getParameter("description");
    String srcFileName = request.getParameter("filename");
    String id =request.getParameter("id");
    try {
        DB data = new DB();
        Connection conn = data.getConnection();
        Statement st = null;
        Statement st1 = null;
        st = conn.createStatement();
        st1 = conn.createStatement();
        String s = application.getRealPath("/");
        st.executeUpdate("update Movie set Name='" + name 
                + "',Type='" + type + "',Rating='" + rating 
                + "',DistrFee='" + distr + "',NumCopies='" + copies
                +"' where Id='" + id + "'");
        String dstFileName = s+"images/movies/" + type + "/movie" + id + ".jpg";
        
        if(srcFileName.equals(dstFileName)){
        
            File srcFile = new File(srcFileName);
            File dstFile = new File(dstFileName);

            FileInputStream srcStrm = new FileInputStream(srcFile);
            FileOutputStream dstStrm = new FileOutputStream(dstFile);

            byte[] buf = new byte[4096];
            int len;
            while ((len = srcStrm.read(buf)) > 0) {
                dstStrm.write(buf, 0, len);
            }
            srcStrm.close();
            dstStrm.close();
        }
        
        String path = s + "images/movies/" + type + "/movie" + id + "Desc.txt";
            //out.println(path);

        File f1 = new File(path);
        FileWriter fw = new FileWriter(f1);
        Writer objWriter = new BufferedWriter(new FileWriter(f1));
        objWriter.write(description);
        
        objWriter.flush();
        objWriter.close();
        
        response.sendRedirect("movieList.jsp");

        }  catch (Exception e) {
    };
%>
